package com.kuiandjie.web;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kuiandjie.entity.Employee;


public class DownLoadHeadServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			HttpSession session = request.getSession();
			//Employee emp = (Employee) session.getAttribute("employee");
			String pic = request.getParameter("pic");
			
			final String PATH = getServletContext().getRealPath("/");
			File file = new File(PATH +  "/head/" +pic);
			
			if(!file.exists()){
				file = new File(PATH +  "/head/" +"users.png");
			}

				BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
				
				byte[] buffer = new byte[1024];
				
				response.setContentType("application/octet-stream");
				OutputStream os = response.getOutputStream(); //获取响应输出流
				
				int len = -1;
				while((len = bis.read(buffer)) != -1) {
					os.write(buffer, 0, len);
				}
				
				os.flush();
				os.close();
				bis.close();
				
			
	
		
	}

}
